import dayjs from 'dayjs'
import rt from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
import store from '../store'
import { App } from 'vue'
export const dateFilter = (val: string, format = 'YYYY-MM-DD') => {
  return dayjs(val).format(format)
}
// 相对时间
dayjs.extend(rt)
function relativeTime(val: any) {
  return dayjs()
    .locale(store.getters.language === 'zh' ? 'zh-cn' : 'en')
    .to(dayjs(val))
}

export default (app: App) => {
  app.config.globalProperties.$filters = {
    dateFilter,
    relativeTime
  }
}
